package cn.tedu.javagame.ball;

public class Board {
    int x,y,width,height;

    // 构造
    public Board(){
        this.x = 700;
        this.y = 520;
        this.width = 300;
        this.height = 20;
    }
    // 获取板的中心位置
    public int getCenterX() {
        return this.x + this.width / 2;
    }
    //行为
    public void move(int x ){
        this.x = x;
    }
    public void catchBall(Ball ball){
        // 碰撞检测
        if ((ball.x>=this.x)&&(ball.x<=this.x+width)&&(ball.y -ball.length<=this.y)&&(ball.y+ball.length>=this.y)) {
            // 根据球的当前状态更新球的状态，实现反弹
            if (ball.state == 2) {
                ball.state = 0;
            } else if (ball.state == 3) {
                ball.state = 1;
            }
            ball.changeColor();
        }
    }
}
